<form method="post" class="form-horizontal">
  <div class="form-group">
    <label class="col-sm-2 control-label">客户cid</label>
    <div class="col-sm-2">
      <input name="cid" type="text" class="form-control" value="{$cid}">
    </div>
  </div>
  <div class="form-group">
    <label class="col-sm-2 control-label">开始时间</label>
    <div class="col-sm-2">
      <input name="stime" type="text" class="form-control" value="{$startTime|date='Y-m-d H:i:s',###}">
    </div>
  </div>
  <div class="form-group">
    <label class="col-sm-2 control-label">结束时间</label>
    <div class="col-sm-2">
      <input name="etime" type="text" class="form-control" value="{$endTime|date='Y-m-d H:i:s',###}">
    </div>
  </div>
  <div class="form-group">
    <div class="col-sm-offset-2 col-sm-8">
      <button type="submit" class="btn btn-primary" data-loading-txt="提交中，请稍后……" data-ajax-url="__CONTROLLER__/indexPost" data-after-callback="after_callback">查询</button>
	  <a id="view" href="__CONTROLLER__/showUserSales" style="display:none;" class="btn btn-primary">查看结果</a>
	  <label id="load" style="display:none;" class="label label-info">LOADING...</label>
    </div>
  </div>
</form>

<script type="text/javascript">

var userList = null,
	count = 0,
	i = 0,
	timer = 0;

function after_callback(data) {
	if ( data.error == 0) {
		userList = data.extra;
		count = userList.length;
		i = 0;
		clearTimeout(timer);
		$("#view").hide();
		$("#load").show();
		
		(function($) {
			(function doing() {
				var data = {
					'id': userList[i],
					'stime': $("input[name='stime']").val(),
					'etime': $("input[name='etime']").val()
				};
				$.ajax({
					'url': '__CONTROLLER__/ajaxUserSales',
					'type': 'post',
					'data': data,
					'success': function(res) {
						if ( !res.error ) {
							if ( i == count ) {
								$("#load").hide();
								$("#view").show();
								clearTimeout(timer);
							} else {
								$("#load").html("LOADING...("+(i+1)+'/'+count+")");
								i++;
							}
						}
						timer = setTimeout(doing, 1);
					}, 
					'error': function() {
						timer = setTimeout(doing, 1);
					}
				});
			})();
		})(jQuery)
		
	}
}
</script>